<?php
declare (strict_types = 1);

namespace app\shop\controller;

use app\common\service\GoodsClassService\GoodsClassService;
use app\Normal;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;

/**
 * 商品分类
 * @Group("GoodsClass")
 * @Middleware({shopMiddileware::class})
 */

class GoodsClass extends \app\BaseShopController
{

    /**
     * 商品分类列表
     * @Route("goodsClassLists",method="GET")
     * @return void
     */
    public function goodsClassLists(){
        $result = callApi(GoodsClassService::class, 'goodsClassLists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 全部商品分类列表，用于下拉框筛选
     * @Route("allGoodsClassLists",method="GET")
     * @return void
     */
    public function allGoodsClassLists(){
        $result = callApi(GoodsClassService::class, 'allGoodsClassLists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 新增商品分类
     * @Route("addGoodsClass",method="POST")
     * @return void
     */
    public function addGoodsClass(){
        $result = callApi(GoodsClassService::class, 'addGoodsClass',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增商品分类【'.$this->_all_data['name'].'】','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 商品分类详情
     * @Route("goodsClassInfo/:id",method="GET")
     * @return void
     */
    public function goodsClassInfo(){
        $result = callApi(GoodsClassService::class, 'goodsClassInfo',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 编辑商品分类
     * @Route("editGoodsClass",method="PUT")
     * @return void
     */
    public function editGoodsClass(){
        $result = callApi(GoodsClassService::class, 'editGoodsClass',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'编辑商品分类【'.$this->_all_data['name'].'】','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 删除商品分类
     * @Route("delGoodsClass",method="DELETE")
     * @return void
     */
    public function delGoodsClass(){
        $result = callApi(GoodsClassService::class, 'delGoodsClass',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'删除ID为【'.$this->_all_data['id'].'】的商品分类','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 获取一级商品分类
     * @Route("oneGoodsClass",method="GET")
     * @return void
     */
    public function oneGoodsClass(){
        $result = callApi(GoodsClassService::class, 'oneGoodsClass',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 初始化商品分类
     * @Route("resetGoodsClass",method="GET")
     * @return void
     */
    public function resetGoodsClass(){
        $result = callApi(GoodsClassService::class, 'resetGoodsClass',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'初始化商品分类','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse(Normal::returnCode($result['code'],$result['msg']));
    }

    /**
     * 映射关联分类列表
     * @Route("relevanceLists",method="GET")
     * @return void
     */
    public function relevanceLists(){
        $result = callApi(GoodsClassService::class, 'relevanceLists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 供应商分类列表
     * @Route("supplierGoodsClass",method="GET")
     * @return void
     */
    public function supplierGoodsClass(){
        $result = callApi(GoodsClassService::class, 'supplierGoodsClass',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 提交关联渠道分类
     * @Route("subRelevance",method="POST")
     * @return void
     */
    public function subRelevance(){
        $result = callApi(GoodsClassService::class, 'subRelevance',$this->_all_data);
        if($result == Normal::SUC){
            $this->log(['content'=>'关联渠道分类','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 删除映射关联分类
     * @Route("delRelevance",method="DELETE")
     * @return void
     */
    public function delRelevance(){
        $result = callApi(GoodsClassService::class, 'delRelevance',$this->_all_data);
        if($result == Normal::SUC){
            $this->log(['content'=>'删除ID为【'.$this->_all_data['id'].'】的供应商分类','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
}